/**
 * 
 */
package org.seginfo.httpfuzzer.header.impl;

import org.seginfo.httpfuzzer.header.AttackStrategy;
import org.seginfo.httpfuzzer.header.HeaderPropertyImpl;

/**
 * @author Administrador
 *
 */
public class Host extends HeaderPropertyImpl {
	
	private static final String NAME = "Host2";
	private static final String VALID = "";
	//private static final String WILDCARD = "*/*";
	private static final int BAD_STRING_MIN_LENGTH = 128;
	private static final int BAD_STRING_LENGTH = 256*16;

	/**
	 * @param attackStrategy
	 */
	public Host(AttackStrategy attackStrategy) {
		super(attackStrategy);
		this.value = this.generateValue();
	}

	/**
	 * @see org.seginfo.httpfuzzer.header.HeaderPropertyImpl#getName()
	 */
	public String getName() {
		return NAME;
	}

	/**
	 * @return
	 */
	private String generateValue() {
		
		String rv="";

		double p = Math.random();
		
		if (p<0.2) {
			rv = attackStrategy.getStringAttack(BAD_STRING_MIN_LENGTH, BAD_STRING_LENGTH);	
		}
		else
		{
			boolean bAddPort = (Math.random() < 0.5);
			int nPartCount = (int) (Math.random() * 10);
			
			while (nPartCount>=0)
			{
				rv += attackStrategy.getStringAttack(BAD_STRING_MIN_LENGTH, BAD_STRING_LENGTH);
				if (nPartCount!=0)
				{
					rv += ".";
				}
				nPartCount--;
			}

			if (bAddPort)
			{
				rv += ":" + attackStrategy.getIntegerAttack(30);
			}
		}

		return rv;
	}
}
